#include"SelectSort.h"
#include<stdio.h>
// 选择排序
int Swap(int* a,int* b){
  int temp=*a;
  *a=*b;
  *b=temp;
}
void SelectSort(int* a, int n){
  int begin=0;
  int end = n;
  while(begin<end){
    int min = begin;
    int max = begin;
    int i=0;
    for(i=begin;i<=end;i++){
      if(a[min]>a[i]){
        min=i;
      }
      if(a[max]<a[i]){
        max=i;
      }
    }
    Swap(&a[begin],&a[min]);
    if(begin==max){
      max=min;
    }
    Swap(&a[end],&a[max]);
    begin++;
    end--;
  }
}
int main(){
  int array[]={1,3,5,7,9,2,4,6,8,0};
  int n=sizeof(array)/sizeof(int)-1;
  SelectSort(array,n);
  int i=0;
  for(i=0;i<=n;i++){
    printf("%d ",array[i]);
  }
  printf("\n");
  return 0;
}
